@extends('frontend/layouts/bootstrap')

@section('content')
<style>
.table th, .table td {padding: 4px 8px;}
</style>

<div>
    <span style="font-size: 31.5px;  line-height: 40px;  margin: 10px 0;  font-family: inherit;  font-weight: bold;  color: inherit;  text-rendering: optimizelegibility;  -webkit-margin-before: 0.83em;  -webkit-margin-after: 0.83em;  -webkit-margin-start: 0px;  -webkit-margin-end: 0px;"> Машины мэдээлэл </span>
    {{ link_to_route('car_balance.main.car_list', 'Машины жагсаалт руу', null, array('class' => 'btn btn-info', 'style' => 'float: right; margin: 10px 0;')) }}
    <a href="{{ URL::previous() }}" class="btn btn-info" style="float: right; margin: 10px 10px;">Буцах</a>
    @if ($next != 0 )
    <a class="btn btn-warning" href="{{ route('car_balance.car.car_show', $next) }}" title="Next" style="float: right; margin: 10px 5px;"><i class="icon-long-arrow-right icon-white"></i></a>
    @endif
    @if ($prev != 0 )
    <a class="btn btn-success" href="{{ route('car_balance.car.car_show', $prev) }}" title="Prev" style="float: right; margin: 10px 5px;"><i class="icon-long-arrow-left icon-white"></i></a>
    @endif
</div>
<h4>Үндсэн мэдээлэл @if (Sentry::getUser()->hasAccess(array('admin', 'operator')))  @if ($car->purchase_car_comment) <div style="float:right;font-weight:normal;font-size: medium;color:green;padding:2px 2px 2px 20px;font-size: medium;max-width:900px;">{{ $car->purchase_car_comment }}</div> @endif @endif </h4>
<table class="table table-bordered" id="car-detail">
    <thead style="background-color: #f0f0f0;">
    <th title="Auction name">Auction name</th>
    <th title="Lot no">Lot no</th>
    <th title="Car maker, model">Car maker, model</th>
    <th title="Car year">Car year</th>
    <th title="Car year month">Year month</th>
    <th title="Chasis no">Chasis no</th>
    <th title="Hudaldan avagch">Hudaldan avagch</th>
    <th title="Service company">Service company</th>
    <th title="Container port">Container port</th>
    <th title="Number plate flag">Number plate</th>
    <th title="Container port">Auction sheet</th>
    </thead>
    <tr>
        <td>{{ $car->auction_name }}</td>
        <td>{{ $car->lot_no }}</td>
        <td>{{ $car->car_maker }} {{ $car->car_name }}</td>
        <td>{{ $car->car_year }}</td>
        <td>{{ $car->car_year_month }}</td>
        <td>{{ $car->chasis_no }}</td>
        <td>{{ $car->customer()->first() ? link_to_route('car_balance.customer.show', $car->customer()->first()->name, $car->customer()->first()->id, array()) : 'NULL' }}</td>
        <td>{{ link_to_route('car_balance.service_company.show', $car->service_company_id == '1' ? 'TIC' : 'NMC', $car->service_company_id, array()) }}</td>
        <td>{{ $car->container_port }}</td>
        <td>{{ $car->number_plate_flag ? '<span class="badge badge-success"><i class="icon icon-ok"></i></span>' : '<span class="badge badge-important"><i class="icon icon-remove"></i></span>'}}</td>
        <td>
            @if ( $car->auction_sheet_upload_flag )
                <a target="_blank" style="margin-left: 15px;" class="btn btn-success btn-mini" href="{{route('car_balance.main.display', array('type'=>'auction', 'file'=>'auction_sheet_'.$car->chasis_no.'.pdf'))}}" title="{{ $car->car_year }}-{{ $car->car_name }}-{{ $car->chasis_no; }}"><i class="icon-zoom-in icon-white"></i></a>
            @else
                No pdf file upload
            @endif
        </td>
    </tr>
</table>

<h4>Төлбөр</h4>
<table class="table table-bordered" id="car-detail">
    <thead style="background-color: #f0f0f0;">
    <th style="text-align: center;" title="Purchase price">Purchase price</th>
    <th style="text-align: center;" title="Vat percent">Vat percent</th>
    <th style="text-align: center;" title="Recycle amount">Recycle amount</th>
    <th style="text-align: center;" title="Auction commission">Auction commission</th>
    <th style="text-align: center;" title="Car tax amount">Car tax amount</th>
    <th style="text-align: center;" title="Transport fee">Transport</th>
    <th style="text-align: center;" title="Drayage fee">Drayage</th>
    <th style="text-align: center;" title="Vanning">Vanning</th>
    <th style="text-align: center;" title="Customs">Customs</th>
    <th style="text-align: center;" title="Others">Others</th>
    <th style="text-align: center;" title="BL">BL</th>
    <th style="text-align: center;" title="Tic_send_fee">TIC</th>
    <th style="text-align: center;" title="Payment total amount">Payment total amount</th>
    </thead>
    <tr>
        <td style="text-align: right;">{{ $car->purchase_price ? number_format($car->purchase_price, 0) : 0; }}</td>
        <td style="text-align: right;">{{ number_format(($car->purchase_price*$car->vat_percent)/100, 0); }}</td>
        <td style="text-align: right;">{{ $car->recycle_amount ? number_format($car->recycle_amount, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->auction_commission ? number_format($car->auction_commission, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->car_tax_amount ? number_format($car->car_tax_amount, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->transfer_fee_1 ? number_format($car->transfer_fee_1, 0) : 0; }}<br/>{{ $car->transfer_fee_2 ? number_format($car->transfer_fee_2, 0) : 0; }} </td>
        <td style="text-align: right;">{{ $car->drayage ? number_format($car->drayage, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->vanning_1 ? number_format($car->vanning_1, 0) : 0; }}<br/>{{ $car->vanning_2 ? number_format($car->vanning_2, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->customs ? number_format($car->customs, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->others ? number_format($car->others, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bl_fee ? number_format($car->bl_fee, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->tic_send_fee ? number_format($car->tic_send_fee, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->payment_total_amount ? number_format($car->payment_total_amount , 0) : 0; }}</td>
    </tr>
</table>

@if ( Sentry::getUser()->hasAccess('admin'))
<h4>Нэхэмжлэл</h4>
<table class="table table-bordered" id="car-detail">
    <thead style="background-color: #f0f0f0;">
    <th style="text-align: center;" title="Bill price">Bill price</th>
    <th style="text-align: center;" title="Vat percent">Vat percent</th>
    <th style="text-align: center;" title="Recycle amount">Recycle amount</th>
    <th style="text-align: center;" title="Auction commission">Auction commission</th>
    <th style="text-align: center;" title="Transport fee">Transport fee</th>
    <th style="text-align: center;" title="Vanning">Vanning</th>
    <th style="text-align: center;" title="Others">Others</th>
    <th style="text-align: center;" title="Commission">Commission</th>
    <th style="text-align: center;" title="Payment total amount">Bill total amount</th>
    </thead>
    <tr>
        <td style="text-align: right;">{{ $car->bill_price ? number_format($car->bill_price, 0) : 0; }}</td>
        <td style="text-align: right;">{{ number_format(($car->bill_price*$car->bill_vat)/100, 0); }}</td>
        <td style="text-align: right;">{{ $car->bill_recycle ? number_format($car->bill_recycle, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_rakusatu ? number_format($car->bill_rakusatu, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_transport_fee ? number_format($car->bill_transport_fee, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_vanning ? number_format($car->bill_vanning, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_others ? number_format($car->bill_others, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_commission ? number_format($car->bill_commission, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->bill_total_amount ? number_format($car->bill_total_amount , 0) : 0; }}</td>
    </tr>
</table>
@endif

<h4>Контайнерын мэдээлэл</h4>
<table class="table table-bordered">
    <thead style="background-color: #f0f0f0;">
    <th title="Container id">Container id</th>
    <th title="Container no">Container no</th>
    <th title="Container date">Container date</th>
    </thead>

    <tr>
        <td> @if($car->container_id) <a href="{{ route('car_balance.container.detail', $car->container_id) }}" target=_car> {{ $car->container_id }} </a> @endif </td>
        <td>{{ $car->container_no }}</td>
        <td>{{ $car->container_date }}</td>
    </tr>
</table>

@if ($penalties->count())
<h4>Penalty мэдээлэл</h4>
<table class="table table-bordered">
    <thead style="background-color: #f0f0f0;">
    <th title="Action">Action</th>
    <th title="Penalty date">Penalty date</th>
    <th title="Penalty amount">Penalty amount</th>
    <th title="Penalty type">Penalty type</th>
    </thead>
    @foreach($penalties as $penalty)
    <tr>
        <td>
            @if (!($penalty->bill_id))
                <a class="btn btn-primary btn-mini" href="{{ route('car_balance.car.edit_penalty', array($car->id, $penalty->id)) }}" title="Edit"><i class="icon-dollar icon-white"></i></a>
                <a class="btn btn-danger btn-mini" href="{{ route('car_balance.car.delete_penalty', array($car->id, $penalty->id)) }}" title="Delete"><i class="icon-remove icon-red"></i></a>
            @endif
        </td>
        <td>{{ $penalty->penalty_date }}</td>
        <td>{{ $penalty->penalty_amount ? number_format($penalty->penalty_amount, 0) : 0; }}</td>
        <td>{{ $penalty->penalty_type == '1' ? 'Tulbur udaasan' : 'Auction'}}</td>
    </tr>
    @endforeach
</table>
@endif

@if ($re_auctions->count())
<h4>Auction-д дахин оруулсан тухай мэдээлэл</h4>
<table class="table table-bordered">
    <thead style="background-color: #f0f0f0;">
        <th title="Action">Action</th>
        <th title="Re Auction Date">Date</th>
        <th title="Re Auction Date">Service Company</th>
        <th title="Transport Company">Transport Company</th>
        <th title="Auction name">Auction name</th>
        <th title="Sold Price">Sold Price</th>
        <th title="Sold Vat">Vat</th>
        <th title="Recycle">Recycle</th>
        <th title="Car Tax">Car Tax</th>
        <th title="Transport fee">Transport fee</th>
        <th title="Re Auction Fee">Re Auction Fee</th>
        <th title="Success Fee">Success Fee</th>
        <th title="Total">Total</th>
        <th title="Status">Status</th>
    </thead>
    @foreach($re_auctions as $re_auction)
    <tr>
        <td>
            <a class="btn btn-primary btn-mini" href="{{ route('car_balance.re_auction.edit', $re_auction->id) }}" title="Edit"><i class="icon-dollar icon-white"></i></a>
<!--            <a class="btn btn-danger btn-mini" href="{{ route('car_balance.re_auction.delete', $re_auction->id) }}" title="Delete"><i class="icon-remove icon-red"></i></a>-->
        </td>
        <td>{{ $re_auction->re_auction_date }}</td>
        <td>{{ link_to_route('car_balance.service_company.show', $re_auction->service_company_id == '1' ? 'TIC' : 'NMC', $re_auction->service_company_id, array()) }}</td>
        <td>{{ $re_auction->transport_company_id ? link_to_route('car_balance.transport_company.show', $re_auction->transport_company_id, $re_auction->transport_company_id, array()) : 'NULL' }}</td>
        <td>{{ $re_auction->auction_name }}</td>
        <td>{{ $re_auction->re_auction_sold_price ? number_format($re_auction->re_auction_sold_price, 0) : 0; }}</td>
        <td>{{ number_format(($re_auction->re_auction_sold_price*$re_auction->re_auction_sold_vat)/100, 0); }}</td>
        <td>{{ $re_auction->re_auction_recycle_amount ? number_format($re_auction->re_auction_recycle_amount, 0) : 0; }}</td>
        <td>{{ $re_auction->re_auction_car_tax_amount ? number_format($re_auction->re_auction_car_tax_amount, 0) : 0; }}</td>
        <td>{{ $re_auction->re_auction_transport_fee ? number_format($re_auction->re_auction_transport_fee, 0) : 0; }}</td>
        <td>{{ $re_auction->re_auction_fee ? number_format($re_auction->re_auction_fee, 0) : 0; }}</td>
        <td>{{ $re_auction->re_auction_success_fee ? number_format($re_auction->re_auction_success_fee, 0) : 0; }}</td>
        <td>{{ $re_auction->re_auction_total ? number_format($re_auction->re_auction_total, 0) : 0; }}</td>
        <td>{{ $re_auction->status == '0' ? 'Зарагдаагүй' : 'Зарагдсан' }}</td
    </tr>
    @endforeach
</table>
@endif
<!--<h4>Return info</h4>
<table class="table table-bordered" id="car-detail">
    <thead style="background-color: #f0f0f0;">
    <th style="text-align: center;" title="Pb dif commission">Pb dif commission</th>
    <th style="text-align: center;" title="Pb dif commission nmh">Pb dif commission nmh</th>
    <th style="text-align: center;" title="Pb dif commission tic">Pb dif commission tic</th>
    <th style="text-align: center;" title="Return vat">Return vat</th>
    <th style="text-align: center;" title="Return vat nmh">Return vat nmh</th>
    <th style="text-align: center;" title="Return vat tic">Return vat tic</th>
    <th style="text-align: center;" title="Return vat kg">Return vat kg</th>
    <th style="text-align: center;" title="Return recycle">Return recycle</th>
    <th style="text-align: center;" title="Return recycle nmh">Return recycle nmh</th>
    <th style="text-align: center;" title="Return recycle tic">Return recycle tic</th>
    <th style="text-align: center;" title="Return car tax">Return car tax</th>
    <th style="text-align: center;" title="Tic commission">Tic commission</th>
    <th style="text-align: center;" title="Return liability">Return liability</th>
    <th style="text-align: center;" title="Return weight tax">Return weight tax</th>
    </thead>
    <tr>
        <td style="text-align: right;">{{ $car->pb_dif_commission ? number_format($car->pb_dif_commission, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->pb_dif_commission_nmh ? number_format($car->pb_dif_commission_nmh, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->pb_dif_commission_tic ? number_format($car->pb_dif_commission_tic, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_vat ? number_format($car->return_vat, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_vat_nmh ? number_format($car->return_vat_nmh, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_vat_tic ? number_format($car->return_vat_tic, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_vat_kg ? number_format($car->return_vat_kg, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_recycle ? number_format($car->return_recycle, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_recycle_nmh ? number_format($car->return_recycle_nmh, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_recycle_tic ? number_format($car->return_recycle_tic, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_car_tax ? number_format($car->return_car_tax, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->tic_commission ? number_format($car->tic_commission, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_liability ? number_format($car->return_liability, 0) : 0; }}</td>
        <td style="text-align: right;">{{ $car->return_weight_tax ? number_format($car->return_weight_tax, 0) : 0; }}</td>
    </tr>
</table>-->

@if (Sentry::getUser()->hasAccess(array('admin', 'operator'))) 
{{ Form::open(array('method' => 'GET', 'route' => array('car_balance.car.car_delete', $car->id))) }}
<!--{{ link_to_route('car_balance.main.re_auction', 'ReAuction', $car->id, array('class' => 'btn btn-warning')) }} &nbsp;&nbsp;-->

{{ link_to_route('car_balance.car.car_edit', 'Edit', $car->id, array('class' => 'btn btn-info')) }} &nbsp;&nbsp;
{{ link_to_route('car_balance.car.create_penalty', 'Add Penalty', $car->id, array('class' => 'btn btn-info')) }} &nbsp;&nbsp;
{{ link_to_route('car_balance.main.re_auction', 'Add ReAction', $car->id, array('class' => 'btn btn-info')) }} &nbsp;&nbsp;
<a class="btn btn-info" href="#" id="comment">Comment</a>  &nbsp;&nbsp;
{{ Form::submit('Delete', array('id'=>'delete', 'class' => 'btn btn-danger', 'style'=>'margin-left:30px;')) }}
{{ Form::close() }}
@endif

@if ( $car->auction_sheet_upload_flag )
<iframe width="100%" height="600px" src="{{route('car_balance.main.display', array('type'=>'auction', 'file'=>'auction_sheet_'.$car->chasis_no.'.pdf'))}}"></iframe>
@endif

@stop

@section('pagescripts')
<script type="text/javascript">
$(function(){
  $('form').submit(function(e) {
    var currentForm=this;e.preventDefault();
    bootbox.confirm("Are you sure?", function(result){
      if (result) {currentForm.submit();}
    });
  });
  $('#comment').click(function(e) {
    e.preventDefault();
    var text = $('h4').eq(0).find('div').html();
    bootbox.confirm('<textarea style="width:90%" id="comment_text" >'+(text?text:'')+'</textarea>', function(result) { 
      if (result) {
        $.get('{{route('car_balance.car.update_comment', array($car->id))}}', {q:$('#comment_text').val()}, function(d) { location.reload();});
      }
    });
  });
});

</script>
@stop